/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mythinking;

/**
 *
 * @author jzou
 */
public class Prime {

    int is_prime(int n) {
        int t = (int) (Math.sqrt(n) + 1);
        for (int i = 2; i <= t; i++) {
            if (n % i == 0) {
                return 0;
            }

        }
        return 1;
    }

    public int run(int num) {
        int i, count = 0;

        for (i = 1; i < num; i++) {
            if (this.is_prime(i) == 1) {
                count++;
                System.out.print(i + " ");
            }
        }
        return count;
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        Prime prime = new Prime();
        int[] list = {100, 1000, 10000};
        for (int i : list) {
            int count = prime.run(i);
            System.out.println("Total of %d primes\n" + count);
        }
        System.out.println("用时毫秒:" + (System.currentTimeMillis() - start));
    }
}